<?php
/**
 * 微学院新闻
 */
namespace App\Controller\Member;
use Common\Controller\App\CommonController;
use Common\Model\NewsModel;

class NewsController extends CommonController{

    /**
     * 微学院
     */
    public function getting_started_list(){
        $classid = 26;//I('post.classid'); //新手入门 23    进阶课堂 24 关于活动 25  疑难问题 26
        $keyword = I('post.keyword');
        $page = I('post.page')?I('post.page'):1;
        $limit = I('post.limit')?I('post.limit'):20;
        $num = ($page-1)*$limit;
        $model = new NewsModel();
        $where = '1=1';
        if($keyword){
            $where .= " and title like '%$keyword%'";
        }
        $fields = ['nid', 'title', 'ftitle', 'titlepic', 'smalltext', 'uptime'];
        $list = $model->where("classid=$classid and  $where")->field($fields)->limit($num,$limit)->select();
        foreach($list as $k=>$v){
            $list[$k]['uptime'] = date('Y-m-d H:i:s',$v['uptime']);
        }
        $this->ajaxReturn(['code'=>200,'list'=>$list]);
    }

    /**
     * 微学院详细
     */
    public function getting_started_list_deteil(){
        $id = I('post.id');
        $model = new NewsModel();
        $info = $model->alias('a')->join("left join haiou_news_data as b on b.nid=a.nid")->field("b.con as content,a.titlepic,a.smalltext,a.ftitle,a.title,a.uptime")->where("a.nid=$id")->find();
        if($info['uptime']){
            $info['uptime'] = date('Y-m-d H:i:s',$info['uptime']);
        }

        $this->ajaxReturn(['code'=>200,'info'=>$info]);
    }
}